﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using BSCMFF.Core.DataAccessLayer;

namespace BSCMFF.Web.Pages.Evaluation_Setup
{
    public partial class AssignPKPIsEvaluation : BSCMFF.Core.MultiLanguagePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        private static int userID;
        protected void EmployeeSelectionChanged(object sender, EventArgs e)
        {
            RadComboBoxSelectedIndexChangedEventArgs re = (RadComboBoxSelectedIndexChangedEventArgs)e;

            userID = Int32.Parse(re.Value);

            //BSCEntities context = new BSCEntities();
            //List<Evaluation_Period> es = (from eu in context.Evaluation_User
            //                       where eu.User_FK == userID
            //                              select eu.Evaluation_Period).ToList();

            //RadComboBoxEvaluations.Items.Clear();
            //RadComboBoxEvaluations.DataSource = es;
            //RadComboBoxEvaluations.DataBind();
        }

        protected void RadComboBoxEvaluations_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            int evalID = Int32.Parse(e.Value);

            BSCEntities context = new BSCEntities();


            List<Personal_KPI> pkpis = (from pkpi in context.Personal_KPI
                                        where pkpi.User_FK == userID
                                        select pkpi).ToList();

            List<PKPIsConnection> conns = new List<PKPIsConnection>();
            foreach (Personal_KPI p in pkpis)
            {
                Evaluation_PKPIs eps = (from ep in context.Evaluation_PKPIs
                                        where ep.PKPI_FK == p.Personal_KPI_ID && ep.EEE_FK == evalID
                                        select ep).FirstOrDefault();

                PKPIsConnection pc = new PKPIsConnection();
                pc.Personal_KPI_ID = p.Personal_KPI_ID;
                pc.Name = p.Name;
                pc.Description = p.Description;

                pc.Connection = eps == null ? false : true;
                pc.Weight = eps == null ? 0 : eps.Weight;
                conns.Add(pc);
            }

            RadGrid1.DataSource = conns;// pkpis;
            RadGrid1.DataBind();
        }

        private class PKPIsConnection
        {
            public int Personal_KPI_ID { get; set; }

            public string Name { get; set; }
            public string Description { get; set; }
            public bool Connection { get; set; }
            public int Weight { get; set; }
        }

        protected void RadButtonUpdate_Click(object sender, EventArgs e)
        {
            //RadGrid1.items
            foreach (GridDataItem di in RadGrid1.Items)
            {
                string s = di.DataItem.ToString();
            }
        }
    }
}